package zmee.pur.src.formplugin;

import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;

import java.util.EventObject;

/**
 * @Author: xw
 * @Date: 2022/12/12/20:21
 * @Description: 根据标书编制是否发送公告字段选择公告范围字段
 */
public class SourceNoticeBillPlugin extends AbstractBillPlugIn {

    @Override
    public void afterBindData(EventObject e) {
        super.afterBindData(e);
        boolean check = (boolean) this.getModel().getValue("zmee_check");
        if (check) {
            return;
        }
        this.getModel().setValue("zmee_check", true);
        Object parentId = this.getModel().getValue("parentid");
        //查询标书编制
        DynamicObject bidDoc = BusinessDataServiceHelper.loadSingle(parentId, "src_biddoc");
        if (null == bidDoc) {
            return;
        }
        //是否发送公告
        boolean ispaper = bidDoc.getBoolean("zmee_ispaper");
        if (!ispaper) {
            Object srcBillNo = this.getModel().getValue("srcbillno");
            QFilter filter = new QFilter("srcbillno", "=", srcBillNo);
            DynamicObject souNotice = BusinessDataServiceHelper.loadSingle("sou_notice", "supscope", filter.toArray());
            souNotice.set("supscope", "3");
            SaveServiceHelper.save(new DynamicObject[]{souNotice});
            this.getModel().setValue("supscope", "3");
        }
    }
}
